package com.hongshan.wallet.core.trading

import android.arch.lifecycle.Observer
import android.view.View
import com.hongshan.wallet.BR
import com.hongshan.wallet.MyApplication
import com.hongshan.wallet.R
import com.hongshan.wallet.base.BasePagerAdapter
import com.hongshan.wallet.base.MyFragment
import kotlinx.android.synthetic.main.pager_item_trading.view.*


/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.trading
 * @author   : zhangxx
 * @date     : 2019/3/22
 * @email    : qq957413212@hotmail.com
 */
class TradingPagerAdapter(val act: MyFragment<*, *>) : BasePagerAdapter<TradingPagerViewModel>() {

    val vms = arrayOf(
        TradingPagerViewModel(MyApplication.applicationContext, 0),
        TradingPagerViewModel(MyApplication.applicationContext, 1),
        TradingPagerViewModel(MyApplication.applicationContext, 2)
    )

    override fun getLayoutId(position: Int) = R.layout.pager_item_trading

    override fun getBrId(position: Int) = BR.tradingPvm

    override fun getViewModel(position: Int) = vms[position]

    override fun getCount() = 3

    override fun getPageTitle(position: Int) = vms[position].title

    override fun dispose(view: View, vm: TradingPagerViewModel) {
        super.dispose(view, vm)
//        val loadService = LoadSir.getDefault().register(view)
        vm.refreshComplete.observe(act, Observer {
            view.srlTrading.finishRefresh()
            view.srlTrading.finishLoadMore()
//            if (it == false){
//                loadService.showCallback(HintCallback::class.java)
//            } else{
//                loadService.showSuccess()
//            }
        })

    }
}